<template>
  <div class="home">
    <el-container style="height: 700px">
      <el-header style="height: 100px">
        <el-row type="flex" class="row-bg" justify="end" align="middle">
          <el-col :span="2"> <router-link to="/Login" target="_blank" v-if="isNotlogin">你好，请登录</router-link></el-col>
          <el-col :span="2"> <router-link to="/register" type="danger" v-if="isNotlogin">免费注册</router-link></el-col>
          <el-col :xs="{span:18}" :sm="{span:16}" :md="{span:14}" :lg="{span:12}" :xl="{span:10}"><div class="grid-content bg-purple  menuTop">
            <el-menu  default-active="customerHome" class="el-menu-demo" mode="horizontal" router="true" unique-opened >
              <template v-for="menu in menuList">
                <el-menu-item :index="menu.index" v-if="menu.menu4s=='' || menu.menu4s== null"><span>{{menu.menuname}}</span></el-menu-item>
                <el-submenu :index="menu.id" v-else>
                  <template slot="title">{{menu.menuname}}</template>
                  <template v-for="child in menu.menu4s">
                    <el-menu-item :index="child.index">{{child.name}}</el-menu-item>
                  </template>
                </el-submenu>
              </template>
            </el-menu>
          </div></el-col>
        </el-row>
      </el-header>
      <div class="line"></div>
      <el-container>
        <el-main style="background-color: #ffffff">
          <!--//主界面-->
          <router-view></router-view>
        </el-main>
        <el-footer style="background-color: black">Footer</el-footer>
      </el-container>
    </el-container>
  </div>
</template>
<script>
export default {
  name:'Home',
  data(){
    return{
      isNotlogin:true,
      menuList:''
    }
  },
  methods:{

  },
  mounted(){
    let jwt = localStorage.getItem("jwt");
    console.log(jwt);
    this.$axios.get('api/isLogin',{headers:{'jwt':jwt}}).then(response =>{
      // console.log(response.data);
          if(response.data.code==406){
            this.isNotlogin=true;
          }else if(response.data.code==200){
            this.isNotlogin=false;
          }
    });
    // console.log(this.isNotlogin);
  },
  created:function (){
    let jwt = localStorage.getItem("jwt");
    this.$axios.get('api/menuListCustomer',{headers:{"jwt":jwt}})
        .then(response =>{
          // console.log(response.data);
          if(response.data.code==200){
             // console.log(response.data);
            this.menuList=response.data.data;
          }
        });
  }
}
</script>

<style scoped>

</style>
